<template>
	<view class="box">
		<view class="money_box fcs">
			<view>缴费金额</view>
			<view>¥ {{info.money}}</view>
		</view>
		<view class="type_box">支付方式</view>
		<view class="p_box">
			<radio-group class="radio-pay">
			<view class="fcs i_box">
				<view class="align_center">
					<text class="iconfont iconweixinzhifu" style="color:#09BB07;"> </text>
					<text class="">微信支付</text>
				</view>
				<radio value="wxpay" checked="true" style="transform:scale(0.7);" color="#499AFD" />
			</view>
			</radio-group>
		</view>
		<view class="pay_box" @click="setPay">立即支付</view>
	</view>
</template>

<script>
	export default{
		data(){
			return{
				params:{stime:'',etime:'',room_id:''},
				info:{money:0},
				order:''
			}
		},
		onLoad(e) {
		  	if(e.stime) this.params.stime=e.stime;
			if(e.etime) this.params.etime=e.etime;
			if(e.room_id) this.params.room_id=e.room_id;
			this.getInfo();
		},
		methods:{
			setPay(){
				if(this.order){
					this.pay();
				}else{
					this.submit();
				}
			},
			submit() {
				let form = JSON.parse(JSON.stringify(this.params));
				form.token = uni.getStorageSync('userToken');
				this.$post(this.$api.jfAdd, form, res => {
					let {
						code,
						data,
						msg
					} = res.data;
					if (code != 1) return this.$Toast(msg);
					this.order = data;
					
					if(data.isPay){
						this.pay();
					}else{
						uni.reLaunch({
							url: '/pages/shopcart/paySuccess?type=2',
							success() {
						
							}
						})
					}
				});
			},
			pay() {
				let _=this;
				this.$post(this.$api.jfPay, {
					id: this.order.id,
					token: uni.getStorageSync('userToken')
				}, ress => {
					let {
						code,
						data,
						msg
					} = ress.data;
					if (code != 1) return this.$Toast(msg);
			
					uni.requestPayment({
						provider: 'wxpay',
						timeStamp: data.timeStamp,
						nonceStr: data.nonceStr,
						package: data.package,
						signType: data.signType,
						paySign: data.paySign,
						success: function(res) {
							_.$Toast('支付成功');
							setTimeout(() => {
								uni.reLaunch({
									url: '/pages/fw/jf/index',
									success() {
			
									}
								})
							}, 500)
			
						},
						fail: function(err) {
							_.$Toast('支付取消');
							
						}
					});
				});
			},
			getInfo(){
				this.params.token=uni.getStorageSync('userToken');
				this.$get(this.$api.jfInfo,this.params,res=>{
					let data=res.data;
					if(data.code==1){
						this.info=data.data;
					}
				});
			}
		}
	}
</script>

<style lang="scss" scoped>
	.box{
		box-sizing: border-box;
		padding: 30rpx 0;
	}
	.fcs{
		display: flex;
		align-items: center;
		justify-content: space-between;
	}
	.money_box{
		
		background-color: white;
		box-sizing: border-box;
		padding: 20rpx;
		font-size: 30rpx;
		color: black;
	}
	.type_box{
		box-sizing: border-box;
		padding: 20rpx 20rpx;
		font-size: 28rpx;
		color: #818181;
	}
	.p_box{
		background-color: white;
	}
	.i_box{
		box-sizing: border-box;
		padding: 10rpx 20rpx; 
		font-size: 28rpx;
	}
	.iconweixinzhifu{
		font-size: 60rpx;
		margin-right: 10rpx;
	}
	.pay_box{
		width: 90%;
		background-color:#499AFD;
		color: white;
		margin: 100rpx auto 0 auto;
		text-align: center;
		box-sizing: border-box;
		padding:25rpx 0;
		font-size: 28rpx;
		border-radius: 15rpx;
	}
</style>